﻿using SearchScreen.SDK;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace SearchScreen.ExtendedComponentSample
{
    [Export(typeof(IFrameworkElementFactoryProvider))]
    [ExportMetadata("Field", "RATIO_POWERCHARGE")]
    public class ExtendedSliderProvider : IFrameworkElementFactoryProvider
    {
        public FrameworkElementFactory GetFactory(Binding targetPropertyBinding)
        {
            var elementFactory = new FrameworkElementFactory();
            elementFactory.Type = typeof(Slider);
            elementFactory.SetValue(Slider.WidthProperty, 100d);
            return elementFactory;
        }

        /*
        // Version with a Grid and ColumnDefinition
        public FrameworkElementFactory GetFactory(Binding targetPropertyBinding)
        {
            var gridFactory = new FrameworkElementFactory(typeof(Grid));

            var c = new FrameworkElementFactory(typeof(ColumnDefinition));
            gridFactory.AppendChild(c);

            c = new FrameworkElementFactory(typeof(ColumnDefinition));
            c.SetValue(ColumnDefinition.WidthProperty, new GridLength(250d));
            gridFactory.AppendChild(c);

            var elementFactory = new FrameworkElementFactory();
            elementFactory.Type = typeof(Slider);
            elementFactory.SetBinding(Slider.ValueProperty, targetPropertyBinding);
            elementFactory.SetValue(Slider.MaximumProperty, 100d);
            elementFactory.SetValue(Grid.ColumnProperty, 1);

            gridFactory.AppendChild(elementFactory);

            return gridFactory;
        }
         */
    }
}
